package com.weight.common.util;

import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.weight.system.sysoper.PO.SysOperInfo;
import com.weight.system.user.VO.UserInfoVO;
 

public class UserContext {
	private static final String CURRENT_SYS_OPER_IN_SESSION = "SysOperInfo";
	private static final String CURRENT_USER_IN_SESSION = "UserInfo";
	 
	/**
	 **得到session
	 */
	private static HttpSession getSession(){
		//SpringMVC获取session的方式通过RequestContextHolder
		return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getSession();
	}
	
	/**
	 ** 设置当前用户到session中
	 */
	public static void setCurrebtUser(UserInfoVO currentUser) {
	   getSession().setAttribute(CURRENT_USER_IN_SESSION,currentUser);
	}
	
	/**
	 ** 获取当前用户
	 */
	public static UserInfoVO getCurreentUser() {
		return (UserInfoVO) getSession().getAttribute(CURRENT_USER_IN_SESSION);
	} 
	
	/**
	 ** 设置当前 操作员信息 到session中
	 */
	public static void setCurrebtSysOper(SysOperInfo currentSysOper) {
	   getSession().setAttribute(CURRENT_SYS_OPER_IN_SESSION,currentSysOper);
	}
	
	/**
	 ** 获取当前 操作员信息
	 */
	public static SysOperInfo getCurreentSysOper() {
		return (SysOperInfo) getSession().getAttribute(CURRENT_SYS_OPER_IN_SESSION);
	} 
	
}
